#include <assert.h>
#include <iostream>

#include "BigInteger.h"

/*
Constructor takes an integer value or defaults to 0.
*/
BigInteger::BigInteger(int value)
{
	bigInteger = new unsigned char[1];
	size = 1;
	bigInteger[0] = (char)128;	
}

/*
Shifts are to be accumulated, and then applied when it becomes necessary. A positive shift value indicates a left shift and a negative shift value indicates a right shift.
*/
void BigInteger::operator<<(const BigInteger&)
{
	shift++;

	applyShift();//TODO:This line is for testing purposes only
}

/*
Shifts are to be accumulated, and then applied when it becomes necessary. A positive shift value indicates a left shift and a negative shift value indicates a right shift.
*/
void BigInteger::operator>>(const BigInteger&)
{
	shift--;
}

/*
Function is the interface for shifting. It's only purpose is to decide which direction the shift should be applied.
*/
void BigInteger::applyShift()
{
	if(shift == 0)
		return;

	if(shift > 0)
		shiftLeft();
	else
		shiftRight();
}

/*
Shift left.

Precondition: shift is non-zero
*/
void BigInteger::shiftLeft()
{
	cout << "bigInteger[0]: " << (int)bigInteger[0] << endl;
	cout << "size: " << size << endl;

	unsigned char* bigIntegerCopy;

	if((int)bigInteger[0] >= EIGHT_BIT_MIN)
		bigIntegerCopy = new unsigned char[++size];
	else
		bigIntegerCopy = new unsigned char[size];

	for(int i = size; i > 0; i--)
	{
		if((int)bigInteger[i] >= EIGHT_BIT_MIN)
			bigIntegerCopy[i + 1] = bigInteger[i] + 1;//TODO: This logic is flawed. Figure out how to assign values over.

		bigIntegerCopy[i] = bigInteger[i] * 2;
	}

	delete[] bigInteger;
	bigInteger = bigIntegerCopy;

	cout << "bigInteger[0]: " << (int)bigInteger[0] << endl;
	cout << "size: " << size << endl;
}

/*
Shift right.

Precondition: shift is non-zero
*/
void BigInteger::shiftRight()
{
}
